package o;

import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.huawei.appgallery.foundation.store.bean.spilt.GetApksInfoRequest;
import com.huawei.appgallery.foundation.store.bean.spilt.GetApksInfoRequest.b;
import com.huawei.appgallery.foundation.store.bean.spilt.GetApksInfoResponse;
import com.huawei.appgallery.foundation.store.bean.spilt.GetApksInfoResponse.ModuleInfo;
import com.huawei.appgallery.foundation.store.bean.spilt.GetApksInfoResponse.SplitApkInfo;
import java.util.ArrayList;
import java.util.List;

public class bot extends cgg<GetApksInfoRequest, GetApksInfoResponse> implements bpm {
    private String ʽ;
    private bqf ˊ;
    private final Context ˋ;
    private int ˎ;
    private final bqa ˏ;
    private String ॱ;

    public bot(Context context, bqa o_bqa) {
        this.ˋ = context;
        this.ˏ = o_bqa;
    }

    public void ˋ(boolean z) {
        if (z) {
            ॱ();
        } else {
            this.ˏ.ॱ(5, "Not signed the agreement.");
        }
    }

    public void ˎ(@NonNull String str, @NonNull bqf o_bqf) {
        boc.ˎ.ˋ("DeferredInstallHandler", "deferredInstall, pkgName: " + str + ", modules: " + o_bqf);
        this.ॱ = str;
        this.ˊ = o_bqf;
        this.ˎ = bla.ॱ(this.ˋ, this.ॱ);
        this.ʽ = new bpb().ˏ(this.ॱ).ॱ(this.ˎ).ˊ(this.ˊ).ˏ(20).ˏ();
        if (!ccx.ॱ()) {
            boc.ˎ.ˏ("DeferredInstallHandler", "Require to sign the agreement.");
            bpp.ˏ().ˏ(this);
            new bpq(this.ˋ, this.ॱ).ˎ();
        } else if (!ˏ()) {
            ॱ();
        }
    }

    private boolean ˏ() {
        bol ˊ = bor.ˎ().ˊ(this.ʽ);
        if (ˊ == null) {
            return false;
        }
        boc.ˎ.ˋ("DeferredInstallHandler", "Session already exists.");
        this.ˏ.ˋ(ˊ.ˏ());
        return true;
    }

    private void ॱ() {
        if (TextUtils.isEmpty(this.ॱ) || this.ˊ == null || this.ˊ.ˋ().isEmpty()) {
            boc.ˎ.ˊ("DeferredInstallHandler", "Run to unreachable logic.");
            return;
        }
        b ˊ = new b(this.ˋ).ˎ(this.ॱ).ˊ(bla.ॱ(this.ˋ, this.ॱ));
        for (bqf.b bVar : this.ˊ.ˋ()) {
            ˊ.ˊ(bVar.ˎ(), bVar.ˋ());
        }
        cvt ॱ = ˊ.ॱ();
        if (ॱ.ॱ()) {
            this.ˏ.ॱ(10, "Already installed.");
        } else {
            bqe.ˋ(ॱ, this);
        }
    }

    protected void ˋ(@NonNull GetApksInfoRequest getApksInfoRequest, @NonNull GetApksInfoResponse getApksInfoResponse) {
        if (getApksInfoResponse.ˏ()) {
            List<ModuleInfo> ˊ = getApksInfoResponse.ˊ();
            if (ˊ == null || ˊ.isEmpty()) {
                this.ˏ.ॱ(100, "Empty module-infos.");
                return;
            }
            bpg ˊ2 = new bpg().ˏ(this.ॱ).ˊ(getApksInfoRequest.ˏ());
            ArrayList arrayList = new ArrayList();
            for (ModuleInfo moduleInfo : ˊ) {
                List<SplitApkInfo> ˊ3 = moduleInfo.ˊ();
                if (ˊ3 == null || ˊ3.isEmpty()) {
                    this.ˏ.ॱ(100, "Empty splitApk-infos.");
                    return;
                }
                for (SplitApkInfo splitApkInfo : ˊ3) {
                    if (splitApkInfo.ˊ() <= 0) {
                        this.ˏ.ॱ(100, "Invalid splitApk-size.");
                        return;
                    }
                    ˊ2.ˋ(new bpf().ˏ(moduleInfo.ॱ(), moduleInfo.ˏ()).ˊ(splitApkInfo));
                }
                int ˋ = moduleInfo.ˋ();
                if (ˋ != 0 || "language".equals(moduleInfo.ॱ())) {
                    arrayList.add(Integer.valueOf(ˋ));
                } else {
                    this.ˏ.ॱ(100, "Invalid splitApk-featureTitle.");
                    return;
                }
            }
            ˎ(ˊ2, arrayList);
            return;
        }
        this.ˏ.ॱ(100, "Fail to request 'ApksInfo'.");
    }

    private void ˎ(bpg o_bpg, ArrayList<Integer> arrayList) {
        if (!ˏ()) {
            bol o_bol = new bol(this.ॱ, o_bpg);
            o_bol.ˊ(this.ʽ);
            o_bol.ˎ(arrayList);
            bor.ˎ().ॱ(o_bol);
            this.ˏ.ˋ(o_bol.ˏ());
        }
    }
}
